//var news = require('../models/admin/news').news;
// exports.article = function(req, res, next){
//   news.findById(req.params.news_id,function(e, result){
//     console.log(result);
//     res.render('article',{
//       result : ''
//     })
//   })
// }
var async = require('async');
var mysql = require('../dbs/mysql').connection;
exports.article = function(req, res, next){
	var targetId = req.params.id;
	async.auto({
		article : function(callback){
            var sql = 'SELECT * FROM news WHERE id = ' + targetId;
            mysql.query(sql, function(err,results){
                if(err){
                    callback(null, {})
                }else{
                    callback(null, results[0])
                }
            });
        },
        relation : function(callback){
        	var sql = 'SELECT * FROM news WHERE id < ' + targetId + ' LIMIT 5';
        	mysql.query(sql, function(err,results){
                if(err){
                    callback(null, {})
                }else{
                    callback(null, results)
                }
            });
        }
	},function(e, results){
		res.render('article',{
			"results":results
		})
	})
}